package com.katze.boot.web.controller;

import com.katze.boot.common.domain.GlobalConstant;
import com.katze.boot.plugins.shiro.annotations.RestControllerMapping;
import com.katze.boot.plugins.shiro.annotations.RestRequestMapping;
import com.katze.common.Message;
import com.katze.common.http.Requester;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMethod;

import java.io.IOException;

@RestControllerMapping("article")
public class ArticleController {

    @RestRequestMapping(permits = "article:view")
    public Message queryArticle(String date) throws IOException {
        String data;
        if (StringUtils.isNotBlank(date)) {
            data = Requester.getInstance().init(GlobalConstant.MRYW_DAY_URL + "?dev=1&date=" + date).send(RequestMethod.GET);
        } else {
            data = Requester.getInstance().init(GlobalConstant.MRYW_TODAY_URL + "?dev=1").send(RequestMethod.GET);
        }
        if (data.length() == 0){
            return Message.error("获取文章失败");
        } else {
            return Message.ok("获取文章成功").data(data);
        }
    }
}
